package com.hotel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.auto.JSONAuthentication;
import com.hotel.entity.HoDaka;
import com.hotel.entity.HoHouse;
import com.hotel.entity.HoUser;
import com.hotel.entity.HouseType;
import com.hotel.mapper.HoHouseMapper;
import com.hotel.mapper.HouseTypeMapper;
import com.hotel.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author animal
 * @since 2022-02-28
 */
@RestController
@RequestMapping("/house-type")
public class HouseTypeController extends JSONAuthentication  {
    @Autowired
    HouseTypeMapper houseTypeMapper;
    @Autowired
    HoHouseMapper hoHouseMapper;
    @ApiOperation(value = "根据房间类型查找房间")
    @PostMapping("/findHouseByType")
    public void findById(HttpServletRequest request, HttpServletResponse response,@RequestParam("hotelType") String hotelType,@RequestParam("size") int size,@RequestParam("current") int current)throws  Exception{
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("hotel_type",hotelType);
        HouseType houseType = houseTypeMapper.selectOne(wrapper);
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("type",houseType.getId());
        Page<HoHouse> shUserPage=new Page<>(current,size);
        Page<HoHouse> shUserPages=hoHouseMapper.selectPage(shUserPage,queryWrapper);
        List<HoHouse> list = shUserPages.getRecords();
        int total=hoHouseMapper.selectCount(queryWrapper);
        if(list.size()>0){
            Result ok = Result.ok().data("userList",list).data("total",total);
            this.WriteJSON(request, response, ok);
        } else {
            Result error = Result.error();
            this.WriteJSON(request, response, error);
        }
    }
}

